<?
	include '../inc.php';
	// importing language (
		$rawsettings = fetch("SELECT * FROM settings;");
		$settings = array(); foreach($rawsettings as $i) $settings[$i[0]] = $i[1];
		include '../langs/'.$settings['lang'].'.php';
	// ) importing language
	if(count($_POST)>0 and $_POST['u']!='') {
		$r = fetch('SELECT * FROM users WHERE name LIKE "'.$_POST['u'].'";');
		if(count($r)>0) {
			echo '{r:"fail",title:"'.$lang['existingNameTitle'].'",text:"'.$lang['existingNameText'].'",hotlink:"'.$lang['backToForm'].'"}';
		} else {
			query('INSERT INTO users (name, pass) VALUES ("'.$_POST['u'].'","'.md5($_POST['p']).'");');
			$r = fetch('SELECT LAST_INSERT_ID();');
			$_SESSION['id'] = $r[0][0];
			echo '{r:"ok"}';
		}
	} else {
		echo '{r:"fail",title:"'.$lang['noNameTitle'].'",text:"'.$lang['noNameText'].'",hotlink:"'.$lang['backToForm'].'"}';
	}
?>